package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam>implements SpecParamService {
    @Autowired
    private SpecParamService specParamService;
    @Override
    public List<SpecParamDTO> querySpecParams(Long cid, Long gid, Boolean searching) {


        List<SpecParam> paramList = specParamService.query().eq(cid != null, "category_id", cid)
                .eq(gid != null, "group_id", gid)
                .eq(searching != null, "searching", searching).list();
        return SpecParamDTO.convertEntityList(paramList);
    }

    @Override
    public void saveParam(SpecParamDTO body) {
        specParamService.save(body.toEntity(SpecParam.class));
    }

    @Override
    public void updateParam(SpecParamDTO body) {
        specParamService.updateById(body.toEntity(SpecParam.class));
    }


}
